# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgname=('lz4' 'liblz4' 'liblz4-devel')
pkgver=1.8.2
pkgrel=1
pkgdesc='Very fast lossless compression algorithm'
arch=('i686' 'x86_64')
url='http://www.lz4.org/'
license=('LGPL')
source=(lz4-${pkgver}.tar.gz::"https://github.com/lz4/lz4/archive/v${pkgver}.tar.gz"
        1.8.2-msys-dll.patch
        1.8.2-msys-install.patch)
sha256sums=('0963fbe9ee90acd1d15e9f09e826eaaf8ea0312e854803caf2db0a6dd40f4464'
            '46a1e89d50ac344086f95a2a5075a9b39b3249125854e7e8c7f340c373a23894'
            '062a16f50080057d2c9cd0f193b25066fa0b1eefef992b21918b799d9a63cb09')
options=(!libtool)

prepare() {
  cd ${srcdir}/lz4-${pkgver}

  patch -p1 -i ${srcdir}/1.8.2-msys-dll.patch
  patch -p1 -i ${srcdir}/1.8.2-msys-install.patch
}

build() {
  cd ${srcdir}/lz4-${pkgver}
  make CC=/usr/bin/gcc CFLAGS="${CFLAGS}" EXT=".exe" all
  make DESTDIR=${srcdir}/dest PREFIX=/usr install
}

check() {
  cd ${srcdir}/lz4-${pkgver}
  make check
}

package_lz4() {
  groups=('libraries')
  depends=('gcc-libs' "lz4=${pkgver}")

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*.dll
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_liblz4() {
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_liblz4-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("liblz4=${pkgver}")
  pkgdesc="lz4 headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
